package cn.edu.scau.cmi.front.dao;

import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException;

import cn.edu.scau.cmi.ema.dao.JpaDao;
import cn.edu.scau.cmi.ema.domain.*;
import cn.edu.scau.cmi.ema.domain.base.CmiPagination;
import cn.edu.scau.cmi.front.domain.EventFoodbatch;
import cn.edu.scau.cmi.front.domain.FrontEventPagination;

public interface CmiEventDAO extends JpaDao {
	// 放在CmiAddressDAO里面会保错 但是在这里不会 后期再改回去
	String findAddressNameById(int addressId);

	Set<Event> findEventsByIdDesc(int startResult, int maxRows);
	
	Event findLastEvent();

	List<Calendar> findEventTimes(Set<Event> events);

	List<Foodbatch> findFoodbatchsByEventLimit(int startId, int startResult, int maxRows) throws DataAccessException;

	List<Integer> findEventIdsByEventLimit(int startId, int startResult, int maxRows) throws DataAccessException;

	Integer findEventIdByLimit(int startResult, int maxRows) throws DataAccessException;

	List<Event> findEventByLimit(int startResult, int maxRows) throws DataAccessException;

	List<Object> findEventIdAndFoodbatchByLimit(int startResult, int maxRows) throws DataAccessException;

	List<Object> findEventIdAndFoodbatchByEventNameLimit(String eventName, int startResult, int maxRows)
			throws DataAccessException;

	Set<Event> findEventsWithPictureByFoodtypeIdsDesc(Set<Integer> foodtypeIdSet, int startResult, int maxRows)
			throws DataAccessException;

	Set<Event> findAllEventsDesc(int startResult, int maxRows) throws DataAccessException;

	String findMaxDiscoveryTimeInEventByDiscoveryAddress(Set<Integer> addressIdSet, int startResult, int maxRows)
			throws DataAccessException;

	String findMinDiscoveryTimeInEventByDiscoveryAddress(Set<Integer> addressIdSet, int startResult, int maxRows)
			throws DataAccessException;

	Long countEventsByDiscoveryAddressAndfoodtypeIds(Integer addressId, Set<Integer> foodtypeIdSet, int startResult,
			int maxRows) throws DataAccessException;

	Long countEventsByDiscoveryAddressAndDiscoveryTimeAndfoodtypeIds(Integer addressId, String time,
			Set<Integer> foodtypeIdSet, int startResult, int maxRows) throws DataAccessException;

	Set<Event> findEventsByFoodtypeId(Set<Integer> foodtypeIdSet, int startResult, int maxRows)
			throws DataAccessException;

	Integer countEventsByFoodtypeId(Set<Integer> foodtypeIdSet, int startResult, int maxRows)
			throws DataAccessException;

	// 该方法有唐锦文添加，用于采用分页的方式网站首页获取不同类型(总共6种)的事件
//	public Integer countEventsByDetachedCriteria(CmiPagination page) throws DataAccessException;

//	Integer countEventsByDetachedCriteriaInRange(CmiPagination page) throws DataAccessException;

//	public Integer countEventsByDetachedCriteriaInRange(DetachedCriteria detachedCriteria,CmiPagination page) throws DataAccessException;

	int findEventsByTime(String hql, int startResult, int maxRows);

	LinkedHashSet<Event> findEventsByDetachedCriteria(FrontEventPagination page) throws DataAccessException;

	Set<Picture> findPicturesWithPictureByEventStatusAndFoodtypeIdsDesc(Set<Boolean> eventStatusSet,
			Set<Integer> foodtypeIdSet, int startResult, int maxRows);

	/**
	 * 通过echart表，根据来源地址名和发现地址名对事件进行统计
	 * 
	 * @param addressName
	 * @param addressType event的地址属性名，source 或 discovery
	 * @return
	 */
	Integer countEventByAddressName(String addressName, String addressType);

	/**
	 * 通过echart表，根据(来源地址名和发现地址名)和(来源年份和发现年份)对事件进行统计
	 * 
	 * @param addressName
	 * @param addressType event的地址属性名，source 或 discovery
	 * @return
	 */
	Integer countEventByAddressNameAndYear(String addressName, String addressType, Integer year, String timeType);

	/**
	 * 通过echart表，根据(来源地址名或发现地址名)和map对事件进行统计
	 * 
	 * @param addressName
	 * @param addressType event的地址属性名，source 或 discovery
	 * @param map         额外筛选条件
	 * @return
	 */
	Integer countEventByAddressNameAndMap(String addressName, String addressType, Map<String, String> map);
	
	/**
	 * 通过echart表，根据map对事件进行统计
	 * 
	 * @param map         筛选条件
	 * @return
	 */
	Integer countEventByMap(Map<String, String> map);

	/**
	 * 通过echart表，根据(6个foodtype子库的id)和map对事件进行统计
	 * 
	 * @param foodtypeId foodtype子库的id
	 * @param map        额外筛选条件
	 * @return
	 */
	Integer countEventByFoodtypeIdAndMap(Integer foodtypeId, Map<String, String> map);

	/**
	 * 通过echart表，根据6个foodtype子库的id对事件进行统计
	 * 
	 * @param foodtypeId
	 * @return
	 */
	Integer countEventByFoodtypeId(Integer foodtypeId);

	/**
	 * 通过echart表，根据(来源地址名和发现地址名)和(来源时间和发现时间)对事件进行统计
	 * 
	 * @param addressName
	 * @param addressType event的地址属性名，source 或 discovery
	 * @param timeOfYear  年
	 * @param timeType    time的地址属性名，source 或 discovery
	 * @return
	 */
	Long countEventByAddressNameAndTime(String addressName, String addressType, String timeOfYear, String timeType);

	/**
	 * 通过echart表，根据(来源地址名和发现地址名)和(来源时间和发现时间)对事件进行统计
	 * 
	 * @param addressName
	 * @param addressType event的地址属性名，source 或 discovery
	 * @param timeOfYear  年
	 * @param timeType    time的地址属性名，source 或 discovery
	 * @param map         额外筛选条件
	 * @return
	 */
	Long countEventByAddressNameAndTime(String addressName, String addressType, String timeOfYear, String timeType,
			Map<String, String> map);

	/**
	 * 通过echart表，根据(6个foodtype子库的id)和(来源时间和发现时间)对事件进行统计
	 * 
	 * @param foodtypeId
	 * @param timeOfYear 年
	 * @param timeType   time的地址属性名，source 或 discovery
	 * @return
	 */
	Long countEventByFoodtypeId(Integer foodtypeId, String timeOfYear, String timeType);
	
	/**
	 * 通过echart表，根据(6个foodtype子库的id)和(来源时间和发现时间)对事件进行统计
	 * 
	 * @param foodtypeId
	 * @param timeOfYear 年
	 * @param timeType   time的地址属性名，source 或 discovery
	 * @param map         额外筛选条件
	 * @return
	 */
	Long countEventByFoodtypeId(Integer foodtypeId, String timeOfYear, String timeType, Map<String, String> map);

	Integer countEvent4MapAndBarTmp(Map<String, String> attrMap);

	Integer countEventsByDetachedCriteriaInRange(FrontEventPagination page) throws DataAccessException;

	Set<Event> findEventByStatusAndDescription(boolean isAduit, String description, int startId, int maxQuantity);

	List<Event> findFoodRelativEvents(Integer eventId, int startResult, int maxRows) throws DataAccessException;

	List<Event> findDiscoveryadddressRelativEvents(Integer eventId, int startResult, int maxRows)
			throws DataAccessException;

	List<Event> findSourceAddressRelativEvents(Integer eventId, int startResult, int maxRows)
			throws DataAccessException;

	List<Event> findFoodtypeRelativEvents(Integer eventId, int startResult, int maxRows) throws DataAccessException;

	Long countEcharteventsByDiscoveryaddressAndDiscoverytime(Address discoveryAddress, int year, Foodtype foodtype);

	Long countEcharteventsByFoodtypeAndDiscoverytime(Foodtype foodtype, int year);
	

}
